package com.chenglu.android.payment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.chenglu.android.R;
import com.chenglu.android.common.base.BaseActionBarActivity;
import com.chenglu.android.common.utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author: lyj
 * @Created: by Copyright 2023/11/15 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description： 订单备注
 */
public class OrderEditActivity extends BaseActionBarActivity {

    public static final String EDITCONTENT = "EDITCONTENT";

    @BindView(R.id.et_order_content)
    EditText etOrderContent;
    @BindView(R.id.tv_content_number)
    TextView tvContentNumber;
    @BindView(R.id.btn_comfirm)
    Button btnComfirm;

    String etcontent;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_order_edit;
    }

    @Override
    protected void initView() {
        setCenterText("订单备注");

        setRightText("完成", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.putExtra(EDITCONTENT, etcontent);
                // 设置返回码和返回携带的数据
                setResult(Activity.RESULT_OK, intent);
                // RESULT_OK就是一个默认值，=-1，它说OK就OK吧
                finish();
            }
        });
        etOrderContent.setSelection(etOrderContent.getText().length());

        etOrderContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(s.length()==50){
                    ToastUtils.show("最多输入50个字");
                    return;
                }
                etcontent = s.toString();
                tvContentNumber.setText(s.length()+"");

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });



    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
